﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Agent : MonoBehaviour
{
    public int agentID;
    public Transform target;

    Vector3 prefVelocity;
    Vector3 velocity;

    public int speed;
    public float radius;


    // Start is called before the first frame update
    void Start()
    {
        agentID = RVO3D.RVOSimulator.Instance.AddAgent(transform.position, 15,10,30, radius, speed, velocity);
    }

    // Update is called once per frame
    void Update()
    {
        //transform.LookAt(target);


        prefVelocity =(target.position - transform.position);
        Vector3 velocity1 = (prefVelocity + transform.forward);


        RVO3D.RVOSimulator.Instance.SetAgentPosition(agentID, transform.position);
        RVO3D.RVOSimulator.Instance.SetAgentPrefVelocity(agentID, velocity1);

        Vector3 velocity = RVO3D.RVOSimulator.Instance.GetAgentVelocity(agentID).normalized;


       // float angle = Vector3.Angle(transform.forward.normalized, velocity);




        transform.rotation = Quaternion.LookRotation(Vector3.MoveTowards(transform.forward, velocity, 0.5f * Time.deltaTime));


        transform.position += transform.forward * (speed * Time.deltaTime);
    }
}
